/***************************************************************************
 *   Copyleft 2008-2009 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __ENGINE3D_H__
#define __ENGINE3D_H__

#include "../Externals/vExternals.h"
#include "./Renderer/vRenderers.h"
#include "./Scene/vSceneManager.h"
#include "./Patterns/vSingleton.h"
#include "../Window/vMainWindow.h"
#include "./Resources/vResources.h"
#include "./API/vApis.h"
#include "./Input/vInputSystem.h"
#include "../Macros/vMemoryMacros.h"

namespace Vendetta {
	class vEngine3D: public vSingleton<vEngine3D> {
		friend class vSingleton<vEngine3D>;
	public:
		vEngine3D();

		~vEngine3D();

		vVoid Update();

		vVoid Init(vDeviceInfo* devInfoPtr = vNull);
		
		vVoid Run();
		
		vVoid Render();
		
		vVoid Quit();
		
		vVoid Kill();

		vVoid AddFrameListener(vFrameListener* list);

		inline vMainWindow* MainWindowPtr() const {
			return mpMainWindow;
		}

		inline vResourcesManager* ResourceManagerPtr() const {
			return mpResourceManager;
		}

		inline vApi* ApiPtr() const {
			return mpApi;
		}

		inline vInputSystem* InputSystemPtr() const {
			return mpInputSystem;
		}

		inline vPainter* PainterPtr() const {
			return mpApi->mpPainter;
		}

		inline vRenderer* RendererPtr() const {
			return mpApi->mpRenderer;
		}

		inline vView* ViewPtr() const {
			return mpApi->mpView;
		}

		inline vState* StatePtr() const {
			return mpApi->mpState;
		}

		inline vSceneManager* SceneManagerPtr() const {
			return mpSceneManager;
		}

	protected:
		vEngine3D(const vEngine3D& engine);
		vEngine3D& operator=(const vEngine3D& engine);

	private:
		vVoid drawRoom();
		vVoid setupLights();

	protected:
		vVertexBuffer* mpBuffer;

	private:
		vArray<vFrameListener*>			mFrameListeners;
		vResourcesManager*				mpResourceManager;
		vInputSystem*					mpInputSystem;
		vMainWindow*					mpMainWindow;
		vApi*							mpApi;
		
		vSceneManager*					mpSceneManager;

		int mTextureID;
		vBool							mShallLeave;
	};
}

#endif // __ENGINE3D_H__